diff options
Diffstat (limited to 'app/[lng]/evcp/(evcp)/faq/manage/actions.ts')
| -rw-r--r-- | app/[lng]/evcp/(evcp)/faq/manage/actions.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/app/[lng]/evcp/(evcp)/faq/manage/actions.ts b/app/[lng]/evcp/(evcp)/faq/manage/actions.ts new file mode 100644 index 00000000..bc443a8a --- /dev/null +++ b/app/[lng]/evcp/(evcp)/faq/manage/actions.ts @@ -0,0 +1,48 @@ +'use server';
+
+import { promises as fs } from 'fs';
+import path from 'path';
+import { FaqCategory } from '@/components/faq/FaqCard';
+import { fallbackLng } from '@/i18n/settings';
+
+const FAQ_CONFIG_PATH = path.join(process.cwd(), 'config', 'faqDataConfig.ts');
+
+export async function updateFaqData(lng: string, newData: FaqCategory[]) {
+ try {
+ const fileContent = await fs.readFile(FAQ_CONFIG_PATH, 'utf-8');
+ const dataMatch = fileContent.match(/export const faqCategories[^=]*=\s*(\{[\s\S]*\});/);
+ if (!dataMatch) {
+ throw new Error('FAQ 데이터 형식이 올바르지 않습니다.');
+ }
+
+ const allData = eval(`(${dataMatch[1]})`);
+ const updatedData = {
+ ...allData,
+ [lng]: newData
+ };
+
+ const newFileContent = `import { FaqCategory } from "@/components/faq/FaqCard";\n\ninterface LocalizedFaqCategories {\n [lng: string]: FaqCategory[];\n}\n\nexport const faqCategories: LocalizedFaqCategories = ${JSON.stringify(updatedData, null, 4)};`;
+ await fs.writeFile(FAQ_CONFIG_PATH, newFileContent, 'utf-8');
+
+ return { success: true };
+ } catch (error) {
+ console.error('FAQ 데이터 업데이트 중 오류 발생:', error);
+ return { success: false, error: '데이터 업데이트 중 오류가 발생했습니다.' };
+ }
+}
+
+export async function getFaqData(lng: string): Promise<{ data: FaqCategory[] }> {
+ try {
+ const fileContent = await fs.readFile(FAQ_CONFIG_PATH, 'utf-8');
+ const dataMatch = fileContent.match(/export const faqCategories[^=]*=\s*(\{[\s\S]*\});/);
+ if (!dataMatch) {
+ throw new Error('FAQ 데이터 형식이 올바르지 않습니다.');
+ }
+
+ const allData = eval(`(${dataMatch[1]})`);
+ return { data: allData[lng] || allData[fallbackLng] || [] };
+ } catch (error) {
+ console.error('FAQ 데이터 읽기 중 오류 발생:', error);
+ return { data: [] };
+ }
+}
\ No newline at end of file |
